1. Field of the Invention
The present invention relates generally to methods and apparatuses for transferring data to and from a first memory that is organized according to an object-oriented scheme to a second memory that is organized according to a relational database management scheme.
More specifically, the invention relates in certain embodiments to methods and apparatuses for transferring data to and from a transient storage that is organized according to an object-oriented scheme to a persistent storage that is organized according to a relational database management scheme. In certain embodiments, the relational database in persistent storage is designed by an object server. This includes defining the tables of the relational database as well as the various columns. The object server then stores and retrieves data from the various tables defined in persistent storage according to a hierarchical tree that maps data encapsulated within objects to table locations in the relational database found in persistent storage.
2. Description of the Related Art
There are well known tradeoffs associated with relational database and object-oriented database designs. Relational databases are commonly optimized for fast, efficient searching. This is largely the result of the fact that relational databases are built from a set of tables that contain related columns. The tables are indexed in an efficient manner by the relational database so that searches may be performed in an optimal manner. While organizing information into a complex related set of tables helps speed searching, a thorough knowledge of the tables is required to specify data that is to be retrieved or to specify where data is to be stored. Furthermore, changing the structure of the tables to add a column may require extensive programming and rewriting of existing code. Another problem in many relational database management systems (RDBMSs) is that columns in tables that contain no information or are not used nevertheless take up space in memory.
A standard relational query language, Structured Query Language (SQL) is used to query most popular relational databases. SQL requires that the person who specifies a query know what tables and columns contain the information that is to be compared against the query. For example, in order to look for all customers in a city, the user must know both the name of the table that contains city information and also the name of the column in that table that contains the city information. It is also necessary that the user know the tables that should be joined to accomplish the search. Likewise, in order to store information in the proper column of the proper table, the user must know the name of the table and column in which the information should be stored.
In contrast, it is easier to query, modify and write information to object-oriented databases. Instead of specifying a table and column for storing or retrieving information, related data is encapsulated in an object. The object may be read into memory and all encapsulated data may be readily accessed. Searching, however, is not as efficient as relational database searching. Entire objects are read into memory in order to check the relevant encapsulated data members. Similarly, store operations are performed on entire objects. Thus, this methodology is not very well suited for on-line transaction processing (OLTP) where transaction rates are high but often only portions of the objects are desired.
Attempts to make object-oriented relational databases have for the most part merely added an object-oriented interpretation to a relational database structure. For example, rows in an existing relational database structure may be interpreted as an object, with each column representing an encapsulated data member. This arrangement, however, does not realize the full power of an object-oriented database. For example, inheritance is not supported so subclasses of objects may not be defined. Additionally, the problem of adding data members to objects is not addressed. Still further, adding a column with no data still allocates large chunk of storage for that column, even if the column is never used.
In view of the foregoing, there is a need for methods and apparatuses for taking advantage of the programming, storage and querying ease of an object-oriented database while enjoying the searching speed of a relational database.
Accordingly, the present invention provides an object server that maps data that is represented in transient memory according to an object-oriented scheme to data that is represented in persistent memory according to a relational database scheme. In certain embodiments, the object server generates appropriate tables and columns for a relational database scheme automatically so that an object-oriented scheme generated by a user may be efficiently stored and searched in persistent memory. Preferably, array elements are represented as rows in a table, not as columns so that storage space is not wasted with place holder data.
It should be appreciated that the present invention can be implemented in numerous ways, including as a process, an apparatus, a system, a device, a method, or a computer readable medium. Several inventive embodiments of the present invention are described below.
In one embodiment, the invention provides a computer implemented method of storing objects in a relational database comprising the steps of: defining a class of objects that are to be stored in the relational database, the objects of the class having at least one data member; creating at least one relational database table to store the objects of the class; and mapping each data member to at least one column in the at least one relational database table. Subclasses of objects may be defined that inherit the data members of a parent class. The data members for objects of the subclass are typically stored in additional relational database tables.
In another embodiment, the invention provides a computer implemented method of querying a relational database comprising the steps of: receiving a first query that is object-oriented and specifies information about objects of interest; instantiating a query container object that comprises a query template based on the first query, an array for any arguments in the template query, and an array for any results in the template query; utilizing the query container object, translating the first query into a second query in a relational database query language for accessing the specified information about the objects of interest that are stored by a relational database management system; sending the second query to the relational database management system; and receiving the specified information about the objects of interest from the relational database management system. Additionally, a results container object may be instantiated to store the specified information about the objects of interest.
In another embodiment, the invention provides a computer implemented method of deferring allocation of storage for array elements of objects comprising the steps of: receiving a request to instantiate an object of a class where the class has a definition that specifies a default value for each data member of an array element; allocating storage space for the object without storage space for an array element if the instantiation request does not specify an initial value for any of the data members of the array element; receiving a request to modify a data member of the array element; determining if storage space for the array element has been allocated; if storage space for the array element has not been allocated, allocating storage space for the array element and initializing each data member of the array element to the specified default value; and modifying the data member of the array element as specified in the modification request.
In another embodiment, the invention provides a computer system for storing objects in a relational database comprising: an object-oriented application for receiving a definition of a class of objects that are to be stored in the relational database, the objects being stored in a transient storage; a memory for the transient storage of the objects; an object server for retrieving the objects from the memory and issuing statements in a relational database query language to store data of the objects; and a relational database management system for receiving the statements and storing the data of the objects in persistent storage as relational database tables.
These and other features and advantages of the present invention will be presented in more detail in the following specification of the invention and the accompanying figures which illustrate by way of example the principles of the invention.